package com.example.admin.myapplication;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

public class ImgeAdapter extends ArrayAdapter<Imge> {

   private int rId;
   public ImgeAdapter(Context context, int textViewResourceId, List<Imge> objects) {
       super(context, textViewResourceId, objects);
       rId = textViewResourceId;
   }


   @Override
    public View getView(int position, View convertView, ViewGroup parent) {
       Imge imge = getItem(position);
       View view;
       if (convertView == null) {
           view = LayoutInflater.from(getContext()).inflate(rId, parent, false);
       }else{
           view = convertView;
       }
       ImageView  imgeImage = (ImageView) view.findViewById(R.id.image_imge);
       TextView imgeText = (TextView) view.findViewById(R.id.text_imge);
       imgeImage.setImageResource(imge.getImageId());
       imgeText.setText(imge.getName());
       return view;
   }
}
